import random
class Person(object):
    def __init__(self,personNum,name):
        self.num = personNum
        self.name = name

class Curiculum(object):
    def __init__(self):
        self.d = {}
    def show_course(self):
        print('查看该课程信息')
        d = {};a=[1,2,3,4,5,6];z=101;s={};j=0;c=0
        with open('class', 'r', encoding='utf-8') as f:
            for i in a:
                buf = f.readline()
                d[i] = buf.rstrip()
                if buf:
                    print(buf.rstrip())
                    # pass
                else:
                    break               #随机分配课程,将学号与课程对应,输入学号即可查询课程，j是学生数
    def search(self):
        d = {};a = [1, 2, 3, 4, 5, 6];z = 101;
        s = {};j = 0;c = 0
        with open('class', 'r', encoding='utf-8') as f:
            for i in a:
                buf = f.readline()
                d[i] = buf.rstrip()
            while c < 10:
                while j < 10:
                    x1 = random.choice(a);y = d[x1] + ' ';a.remove(x1);
                    x2 = random.choice(a);y += d[x2] + ' ';a.remove(x2);
                    x3 = random.choice(a);y += d[x3] + ' ';a.remove(x3);
                    s[z] = y;j += 1;z += 1;a = [1, 2, 3, 4, 5, 6]
                    if j%6==0:
                        a = [1, 2, 3, 4, 5, 6]
                c += 1
            self.d = d
            # print(self.d)  # 字典s里写了每个学生分配的课程，字典d里写的是课程的信息
            num = int(input('请输入学生的学号：'))
            q = s[num];print(q)
            self.stuclassinfo=q
class Student(Curiculum):
    def checkinfo(self):
        print('查看全部学生个人信息：学号，姓名，地址');self.studict={};stunum=101;
        with open('students','r',encoding='utf-8') as f:
            for line in f:
                a,b,c = line.strip().split(' ')
                print(f'学号：{a} 姓名：{b} 地址：{c}')
                self.studict[stunum]=' 姓名:'+b+' 地址:'+c
                stunum+=1
            print(self.studict)
    def search_student(self):
        num = input('请输入待查询学生的学号')
        with open('students','r',encoding='utf-8') as f:
            for line in f:
                a,b,c = line.strip().split(' ')
                if a==num:
                    print(f'学号：{a} 姓名：{b} 地址：{c}')
                    break
            else:
                    print('学号输入有误，未查询到该学生')
    def add(self):
        print('为防止课程选错选重，请在加选课程前核实自己当前的课程')
        Curiculum.show_course(self)
        Curiculum.search(self)
        classnum=int(input('请输入你想加选的课程编号'))
        x=self.d[classnum]
        if x:
            print('添加课程成功');print(self.stuclassinfo+x)
        else:
            print('您输入的课程编号不对，添加失败')
class Teacher():
    def teacher_info(self):
        with open('class','r',encoding='utf-8') as f:
            for line in f:
                teacherlist = line.strip().split(' ')
                print(f'{teacherlist[0]}{teacherlist[1]}{teacherlist[2]} {teacherlist[3]} {teacherlist[4]}')
    def search_teacher(self):
        name = input('请输入老师的姓名')
        with open('teacher', 'r', encoding='utf-8') as f:
            for line in f:
                a,b,c= line.strip().split(' ')
                if b== name:
                    print(f'编号:{a} {b} {c}')
                    break
            else:
                print('未查询到该老师的信息')
print('------------欢迎来到学生选课系统-----------------')
print('请选择系统功能\n1.查看全部学生个人信息 2.搜索学生信息 3.查看全部课程信息 4.查看个人课程信息 5.查看老师信息 6.搜索老师信息 7.添加课程 8.退出系统')
stu = Student()
while True :
    choice=int(input('请输入你想使用的功能'))
    if choice==1:
        stu.checkinfo()
    elif choice==2:
        Student().search_student()
    elif choice==3:
        Student().show_course()
    elif choice==4:
        Curiculum().search()
    elif choice==5:
        Teacher().teacher_info()
    elif choice==6:
        Teacher().search_teacher()
    elif choice==7:
        Student().add()
    elif choice==8:
        break



